*Regressions Table 5

********************************************************************************
*Main Results Table 5 Column 1
********************************************************************************

use finaldatasetforregressions.dta, clear
drop if monopoly == 1

xtreg logprice mmc_ek csc_avg pct_major_ind markets_served_origin_TKT markets_served_dest_TKT dummy*, fe vce(robust)

********************************************************************************
*Main Results Table 5 Column 2 
********************************************************************************

use finaldatasetforregressions.dta, clear
drop if monopoly == 1

xtreg mmc_ek markets_served_origin_TKT markets_served_dest_TKT markets_served_origin_TKTAA-markets_served_dest_TKTYX dummy*, fe vce(robust)	

predict residual_mmc, e

*networks plus competitor's weather plus competitor's regional networks
xtreg csc_avg markets_served_origin_TKT markets_served_dest_TKT markets_served_origin_TKTAA-markets_served_dest_TKTYX IVm_worstprcp-IVm_worsttmin IVmktktlevl_airportinUS_reg dummy*, fe vce(robust)

predict residual_csc, e

*networks plus own weather
xtreg pct_major_ind markets_served_origin_TKT markets_served_dest_TKT markets_served_origin_TKTAA-markets_served_dest_TKTYX m_worstprcp-m_worsttmin dummy*, fe vce(robust)

predict residual_regpct, e

*IV reg using control function approach
xtreg logprice mmc_ek csc_avg pct_major_ind residual_mmc residual_csc residual_regpct markets_served_origin_TKT markets_served_dest_TKT dummy*, fe vce(robust)

*bootstrap errors
matrix benchmark_control_coef = (_b[mmc_ek], _b[csc_avg], _b[pct_major_ind], _b[residual_mmc], _b[residual_csc], _b[residual_regpct])

drop residual_mmc
drop residual_csc
drop residual_regpct

capture program drop benchmark_control
program define benchmark_control, rclass
	
	preserve
	
	*take bootstrapped sample
	bsample 
	
	*first-stage regression
	xtreg mmc_ek markets_served_origin_TKT markets_served_dest_TKT markets_served_origin_TKTAA-markets_served_dest_TKTYX dummy*, fe vce(robust)
	
	*find mmc residual from first stage
	predict residual_mmc, e

	xtreg csc_avg markets_served_origin_TKT markets_served_dest_TKT markets_served_origin_TKTAA-markets_served_dest_TKTYX IVm_worstprcp-IVm_worsttmin IVmktktlevl_airportinUS_reg dummy*, fe vce(robust)

predict residual_csc, e
	
	xtreg pct_major_ind markets_served_origin_TKT markets_served_dest_TKT markets_served_origin_TKTAA-markets_served_dest_TKTYX m_worstprcp-m_worsttmin dummy*, fe vce(robust)

	predict residual_regpct, e
	
	*second stage
	xtreg logprice mmc_ek csc_avg pct_major_ind residual_mmc residual_csc residual_regpct markets_served_origin_TKT markets_served_dest_TKT dummy*, fe vce(robust)
	
	*save coefficient on mmc_ek
	return scalar mmc_ek_coef = _b[mmc_ek]
	return scalar residual_mmc_coef = _b[residual_mmc]
	return scalar csc_coef = _b[csc_avg]
	return scalar residual_csc_coef = _b[residual_csc]
	return scalar regpct_coef = _b[pct_major_ind]
	return scalar residual_regpct_coef = _b[residual_regpct]
	
	restore
	
end

*now try bootstrap
simulate mmc_ek_coef = _b[mmc_ek] csc_coef = _b[csc_avg] regpct_coef = _b[pct_major_ind] residual_mmc_coef = _b[residual_mmc] residual_csc_coef = _b[residual_csc] residual_regpct_coef = _b[residual_regpct], reps(1000) seed(1234): benchmark_control 

bstat, stat(benchmark_control_coef)

********************************************************************************
*Main Results Table 5 Column 3
********************************************************************************

use finaldatasetforregressions.dta, clear
drop if monopoly == 1

gen dummy_pre_2003 = 0
replace dummy_pre_2003 = 1 if year <= 2003

gen dummy_2004_2012 = 0
replace dummy_2004_2012 = 1 if year >= 2004 & year <= 2012

gen dummy_2013_2016 = 0
replace dummy_2013_2016 = 1 if year > 2012

gen dummy_2011_2016 = 0
replace dummy_2011_2016 = 1 if year >= 2011

gen dummy_pre_2010 = 0
replace dummy_pre_2010 = 1 if year <= 2010

gen csc_avg_pre_2003 = csc_avg*dummy_pre_2003
gen csc_avg_2004_2012 = csc_avg*dummy_2004_2012
gen csc_avg_2013_2016 = csc_avg*dummy_2013_2016

gen regpct_pre_2003 = pct_major_ind*dummy_pre_2003
gen reg_pct_2004_2012 = pct_major_ind*dummy_2004_2012
gen reg_pct_2013_2016 = pct_major_ind*dummy_2013_2016

gen mmc_pre_2010 = mmc_ek*dummy_pre_2010
gen mmc_2011_2016 = mmc_ek*dummy_2011_2016

xtreg mmc_ek markets_served_origin_TKT markets_served_dest_TKT markets_served_origin_TKTAA-markets_served_dest_TKTYX dummy*, fe vce(robust)	

predict residual_mmc, e

*networks plus competitor's weather plus competitor's regional networks
xtreg csc_avg markets_served_origin_TKT markets_served_dest_TKT markets_served_origin_TKTAA-markets_served_dest_TKTYX IVm_worstprcp-IVm_worsttmin IVmktktlevl_airportinUS_reg dummy*, fe vce(robust)

predict residual_csc, e

*networks plus own weather
xtreg pct_major_ind markets_served_origin_TKT markets_served_dest_TKT markets_served_origin_TKTAA-markets_served_dest_TKTYX m_worstprcp-m_worsttmin dummy*, fe vce(robust)

predict residual_regpct, e

*IV reg using control function approach
xtreg logprice mmc_ek mmc_2011_2016 csc_avg csc_avg_2004_2012 csc_avg_2013_2016 pct_major_ind reg_pct_2004_2012 reg_pct_2013_2016 residual_mmc residual_csc residual_regpct markets_served_origin_TKT markets_served_dest_TKT dummy*, fe vce(robust)

matrix trends_control_coef = (_b[mmc_ek], _b[mmc_2011_2016], _b[csc_avg], _b[csc_avg_2004_2012], _b[csc_avg_2013_2016], _b[pct_major_ind], _b[reg_pct_2004_2012], _b[reg_pct_2013_2016], _b[residual_mmc], _b[residual_csc], _b[residual_regpct])

drop residual_mmc
drop residual_csc
drop residual_regpct

capture program drop trends_control
program define trends_control, rclass
	
	preserve
	
	*take bootstrapped sample
	bsample 
	
	*first-stage regression
	xtreg mmc_ek markets_served_origin_TKT markets_served_dest_TKT markets_served_origin_TKTAA-markets_served_dest_TKTYX dummy*, fe vce(robust)
	
	*find mmc residual from first stage
	predict residual_mmc, e

	xtreg csc_avg markets_served_origin_TKT markets_served_dest_TKT markets_served_origin_TKTAA-markets_served_dest_TKTYX IVm_worstprcp-IVm_worsttmin IVmktktlevl_airportinUS_reg dummy*, fe vce(robust)

predict residual_csc, e
	
	xtreg pct_major_ind markets_served_origin_TKT markets_served_dest_TKT markets_served_origin_TKTAA-markets_served_dest_TKTYX m_worstprcp-m_worsttmin dummy*, fe vce(robust)

	predict residual_regpct, e
	
	*second stage
	xtreg logprice mmc_ek mmc_2011_2016 csc_avg csc_avg_2004_2012 csc_avg_2013_2016 pct_major_ind reg_pct_2004_2012 reg_pct_2013_2016 residual_mmc residual_csc residual_regpct markets_served_origin_TKT markets_served_dest_TKT dummy*, fe vce(robust)
	
	*save coefficient on mmc_ek
	return scalar mmc_ek_coef = _b[mmc_ek]
	return scalar mmc_2011_2016_coef = _b[mmc_2011_2016]
	return scalar residual_mmc_coef = _b[residual_mmc]
	return scalar csc_coef = _b[csc_avg]
	return scalar csc_2004_2012_coef = _b[csc_avg_2004_2012]
	return scalar csc_2013_2016_coef = _b[csc_avg_2013_2016]
	return scalar residual_csc_coef = _b[residual_csc]
	return scalar regpct_coef = _b[pct_major_ind]
	return scalar regpct_2004_2012_coef = _b[reg_pct_2004_2012]
	return scalar regpct_2013_2016_coef = _b[reg_pct_2013_2016]
	return scalar residual_regpct_coef = _b[residual_regpct]
	
	restore
	
end

simulate mmc_ek_coef = _b[mmc_ek] mmc_2011_2016_coef = _b[mmc_2011_2016] csc_coef = _b[csc_avg] csc_2004_2012_coef = _b[csc_avg_2004_2012] csc_2013_2016_coef = _b[csc_avg_2013_2016] regpct_coef = _b[pct_major_ind] regpct_2004_2012_coef = _b[reg_pct_2004_2012] regpct_2013_2016_coef = _b[reg_pct_2013_2016] residual_mmc_coef = _b[residual_mmc] residual_csc_coef = _b[residual_csc] residual_regpct_coef = _b[residual_regpct], reps(1000) seed(1234): trends_control 

bstat, stat(trends_control_coef)

********************************************************************************
*Main Results Table 5 Column 4
********************************************************************************

*construct quantity variable
use maindataset, clear

ge observation=_n
sort observation 

reshape long opcarrier segment, i(observation) j(seqnum)
drop if segment==""

*sum number of passengers by market by tkcarrier
keep observation market tkcarrier mktpass_tkopcarrier year
duplicates drop
bysort market tkcarrier year: egen totalpassengers=sum(mktpass_tkopcarrier)
keep tkcarrier market totalpassengers year
duplicates drop

*merge quantity information with regression dataset
merge 1:1 market tkcarrier year using finaldatasetforregressions.dta
drop if _merge == 1
drop _merge

drop if monopoly == 1

gen log_totalpassengers = log(totalpassengers)

***Regressions
xtreg mmc_ek markets_served_origin_TKT markets_served_dest_TKT markets_served_origin_TKTAA-markets_served_dest_TKTYX dummy* if monopoly == 0, fe vce(robust)
predict residual_mmc, e

*csc first_stage
xtreg csc_avg markets_served_origin_TKT markets_served_dest_TKT markets_served_origin_TKTAA-markets_served_dest_TKTYX IVm_worstprcp-IVm_worsttmin IVmktktlevl_airportinUS_reg dummy* if monopoly == 0, fe vce(robust)
predict residual_csc, e

*reg pct first-stage
xtreg pct_major_ind markets_served_origin_TKT markets_served_dest_TKT markets_served_origin_TKTAA-markets_served_dest_TKTYX m_worstprcp-m_worsttmin dummy* if monopoly == 0, fe vce(robust)
predict residual_regpct, e

*IV control function
xtreg log_totalpassengers mmc_ek csc_avg pct_major_ind residual_mmc residual_csc residual_regpct markets_served_origin_TKT markets_served_dest_TKT dummy* if monopoly == 0, fe vce(robust)

*bootstrap errors
matrix benchmark_control_coef = (_b[mmc_ek], _b[csc_avg], _b[pct_major_ind], _b[residual_mmc], _b[residual_csc], _b[residual_regpct])

drop residual_mmc
drop residual_csc
drop residual_regpct

capture program drop benchmark_control
program define benchmark_control, rclass
	
	preserve
	
	*take bootstrapped sample
	bsample 
	
	*first-stage regression
	xtreg mmc_ek markets_served_origin_TKT markets_served_dest_TKT markets_served_origin_TKTAA-markets_served_dest_TKTYX dummy*, fe vce(robust)
	
	*find mmc residual from first stage
	predict residual_mmc, e

	xtreg csc_avg markets_served_origin_TKT markets_served_dest_TKT markets_served_origin_TKTAA-markets_served_dest_TKTYX IVm_worstprcp-IVm_worsttmin IVmktktlevl_airportinUS_reg dummy*, fe vce(robust)

predict residual_csc, e
	
	xtreg pct_major_ind markets_served_origin_TKT markets_served_dest_TKT markets_served_origin_TKTAA-markets_served_dest_TKTYX m_worstprcp-m_worsttmin dummy*, fe vce(robust)

	predict residual_regpct, e
	
	*second stage
	xtreg log_totalpassengers mmc_ek csc_avg pct_major_ind residual_mmc residual_csc residual_regpct markets_served_origin_TKT markets_served_dest_TKT dummy*, fe vce(robust)
	
	*save coefficient on mmc_ek
	return scalar mmc_ek_coef = _b[mmc_ek]
	return scalar residual_mmc_coef = _b[residual_mmc]
	return scalar csc_coef = _b[csc_avg]
	return scalar residual_csc_coef = _b[residual_csc]
	return scalar regpct_coef = _b[pct_major_ind]
	return scalar residual_regpct_coef = _b[residual_regpct]
	
	restore
	
end

*now bootstrap
simulate mmc_ek_coef = _b[mmc_ek] csc_coef = _b[csc_avg] regpct_coef = _b[pct_major_ind] residual_mmc_coef = _b[residual_mmc] residual_csc_coef = _b[residual_csc] residual_regpct_coef = _b[residual_regpct], reps(1000) seed(1234): benchmark_control 

bstat, stat(benchmark_control_coef)

********************************************************************************
*Main Results Table 5 Column 5
********************************************************************************

*construct quantity variable
use maindataset, clear

ge observation=_n
sort observation 

reshape long opcarrier segment, i(observation) j(seqnum)
drop if segment==""

*sum number of passengers by market by tkcarrier
keep observation market tkcarrier mktpass_tkopcarrier year
duplicates drop
bysort market tkcarrier year: egen totalpassengers=sum(mktpass_tkopcarrier)
keep tkcarrier market totalpassengers year
duplicates drop

*merge quantity information with regression dataset
merge 1:1 market tkcarrier year using finaldatasetforregressions.dta
drop if _merge == 1
drop _merge

drop if monopoly == 1

gen log_totalpassengers = log(totalpassengers)

gen dummy_pre_2003 = 0
replace dummy_pre_2003 = 1 if year <= 2003

gen dummy_2004_2012 = 0
replace dummy_2004_2012 = 1 if year >= 2004 & year <= 2012

gen dummy_2013_2016 = 0
replace dummy_2013_2016 = 1 if year > 2012

gen dummy_2011_2016 = 0
replace dummy_2011_2016 = 1 if year >= 2011

gen dummy_pre_2010 = 0
replace dummy_pre_2010 = 1 if year <= 2010

gen csc_avg_pre_2003 = csc_avg*dummy_pre_2003
gen csc_avg_2004_2012 = csc_avg*dummy_2004_2012
gen csc_avg_2013_2016 = csc_avg*dummy_2013_2016

gen regpct_pre_2003 = pct_major_ind*dummy_pre_2003
gen reg_pct_2004_2012 = pct_major_ind*dummy_2004_2012
gen reg_pct_2013_2016 = pct_major_ind*dummy_2013_2016

gen mmc_pre_2010 = mmc_ek*dummy_pre_2010
gen mmc_2011_2016 = mmc_ek*dummy_2011_2016

***
*Regressions
xtreg mmc_ek markets_served_origin_TKT markets_served_dest_TKT markets_served_origin_TKTAA-markets_served_dest_TKTYX dummy*, fe vce(robust)	

predict residual_mmc, e

*networks plus competitor's weather plus competitor's regional networks
xtreg csc_avg markets_served_origin_TKT markets_served_dest_TKT markets_served_origin_TKTAA-markets_served_dest_TKTYX IVm_worstprcp-IVm_worsttmin IVmktktlevl_airportinUS_reg dummy*, fe vce(robust)

predict residual_csc, e

*networks plus own weather
xtreg pct_major_ind markets_served_origin_TKT markets_served_dest_TKT markets_served_origin_TKTAA-markets_served_dest_TKTYX m_worstprcp-m_worsttmin dummy*, fe vce(robust)

predict residual_regpct, e

*IV reg using control function approach
xtreg log_totalpassengers mmc_ek mmc_2011_2016 csc_avg csc_avg_2004_2012 csc_avg_2013_2016 pct_major_ind reg_pct_2004_2012 reg_pct_2013_2016 residual_mmc residual_csc residual_regpct markets_served_origin_TKT markets_served_dest_TKT dummy*, fe vce(robust)

matrix trends_control_coef = (_b[mmc_ek], _b[mmc_2011_2016], _b[csc_avg], _b[csc_avg_2004_2012], _b[csc_avg_2013_2016], _b[pct_major_ind], _b[reg_pct_2004_2012], _b[reg_pct_2013_2016], _b[residual_mmc], _b[residual_csc], _b[residual_regpct])

drop residual_mmc
drop residual_csc
drop residual_regpct

capture program drop trends_control
program define trends_control, rclass
	
	preserve
	
	*take bootstrapped sample
	bsample 
	
	*first-stage regression
	xtreg mmc_ek markets_served_origin_TKT markets_served_dest_TKT markets_served_origin_TKTAA-markets_served_dest_TKTYX dummy*, fe vce(robust)
	
	*find mmc residual from first stage
	predict residual_mmc, e

	xtreg csc_avg markets_served_origin_TKT markets_served_dest_TKT markets_served_origin_TKTAA-markets_served_dest_TKTYX IVm_worstprcp-IVm_worsttmin IVmktktlevl_airportinUS_reg dummy*, fe vce(robust)

predict residual_csc, e
	
	xtreg pct_major_ind markets_served_origin_TKT markets_served_dest_TKT markets_served_origin_TKTAA-markets_served_dest_TKTYX m_worstprcp-m_worsttmin dummy*, fe vce(robust)

	predict residual_regpct, e
	
	*second stage
	xtreg log_totalpassengers mmc_ek mmc_2011_2016 csc_avg csc_avg_2004_2012 csc_avg_2013_2016 pct_major_ind reg_pct_2004_2012 reg_pct_2013_2016 residual_mmc residual_csc residual_regpct markets_served_origin_TKT markets_served_dest_TKT dummy*, fe vce(robust)
	
	*save coefficient on mmc_ek
	return scalar mmc_ek_coef = _b[mmc_ek]
	return scalar mmc_2011_2016_coef = _b[mmc_2011_2016]
	return scalar residual_mmc_coef = _b[residual_mmc]
	return scalar csc_coef = _b[csc_avg]
	return scalar csc_2004_2012_coef = _b[csc_avg_2004_2012]
	return scalar csc_2013_2016_coef = _b[csc_avg_2013_2016]
	return scalar residual_csc_coef = _b[residual_csc]
	return scalar regpct_coef = _b[pct_major_ind]
	return scalar regpct_2004_2012_coef = _b[reg_pct_2004_2012]
	return scalar regpct_2013_2016_coef = _b[reg_pct_2013_2016]
	return scalar residual_regpct_coef = _b[residual_regpct]
	
	restore
	
end

simulate mmc_ek_coef = _b[mmc_ek] mmc_2011_2016_coef = _b[mmc_2011_2016] csc_coef = _b[csc_avg] csc_2004_2012_coef = _b[csc_avg_2004_2012] csc_2013_2016_coef = _b[csc_avg_2013_2016] regpct_coef = _b[pct_major_ind] regpct_2004_2012_coef = _b[reg_pct_2004_2012] regpct_2013_2016_coef = _b[reg_pct_2013_2016] residual_mmc_coef = _b[residual_mmc] residual_csc_coef = _b[residual_csc] residual_regpct_coef = _b[residual_regpct], reps(1000) seed(1234): trends_control 

bstat, stat(trends_control_coef)

********************************************************************************
*Main Results Table 5 Column 6
********************************************************************************

use finaldatasetforregressions.dta, clear
drop if monopoly == 1

xtreg mmc_ek markets_served_origin_TKT markets_served_dest_TKT markets_served_origin_TKTAA-markets_served_dest_TKTYX dummy*, fe vce(robust)	

predict residual_mmc, e

*networks plus competitor's weather plus competitor's regional networks
xtreg csc_count_avg markets_served_origin_TKT markets_served_dest_TKT markets_served_origin_TKTAA-markets_served_dest_TKTYX IVm_worstprcp-IVm_worsttmin IVmktktlevl_airportinUS_reg dummy*, fe vce(robust)

predict residual_csc, e

*networks plus own weather
xtreg pct_major_ind markets_served_origin_TKT markets_served_dest_TKT markets_served_origin_TKTAA-markets_served_dest_TKTYX m_worstprcp-m_worsttmin dummy*, fe vce(robust)

predict residual_regpct, e

*IV reg using control function approach
xtreg logprice mmc_ek csc_count_avg pct_major_ind residual_mmc residual_csc residual_regpct markets_served_origin_TKT markets_served_dest_TKT dummy*, fe vce(robust)

matrix csc_count_coef = (_b[mmc_ek], _b[csc_count_avg], _b[pct_major_ind], _b[residual_mmc], _b[residual_csc], _b[residual_regpct])

drop residual_mmc
drop residual_csc
drop residual_regpct

capture program drop count_control
program define count_control, rclass
	
	preserve
	
	*take bootstrapped sample
	bsample 
	
	*first-stage regression
	xtreg mmc_ek markets_served_origin_TKT markets_served_dest_TKT markets_served_origin_TKTAA-markets_served_dest_TKTYX dummy*, fe vce(robust)
	
	*find mmc residual from first stage
	predict residual_mmc, e

	xtreg csc_count_avg markets_served_origin_TKT markets_served_dest_TKT markets_served_origin_TKTAA-markets_served_dest_TKTYX IVm_worstprcp-IVm_worsttmin IVmktktlevl_airportinUS_reg dummy*, fe vce(robust)

predict residual_csc, e
	
	xtreg pct_major_ind markets_served_origin_TKT markets_served_dest_TKT markets_served_origin_TKTAA-markets_served_dest_TKTYX m_worstprcp-m_worsttmin dummy*, fe vce(robust)

	predict residual_regpct, e
	
	*second stage
	xtreg logprice mmc_ek csc_count_avg pct_major_ind residual_mmc residual_csc residual_regpct markets_served_origin_TKT markets_served_dest_TKT dummy*, fe vce(robust)
	
	*save coefficient on mmc_ek
	return scalar mmc_ek_coef = _b[mmc_ek]
	return scalar residual_mmc_coef = _b[residual_mmc]
	return scalar csccount_coef = _b[csc_count_avg]
	return scalar residual_csc_coef = _b[residual_csc]
	return scalar regpct_coef = _b[pct_major_ind]
	return scalar residual_regpct_coef = _b[residual_regpct]
	
	restore
	
end

*now try bootstrap
simulate mmc_ek_coef = _b[mmc_ek] csccount_coef = _b[csc_count_avg] regpct_coef = _b[pct_major_ind] residual_mmc_coef = _b[residual_mmc] residual_csc_coef = _b[residual_csc] residual_regpct_coef = _b[residual_regpct], reps(1000) seed(1234): count_control 

bstat, stat(csc_count_coef)

********************************************************************************
*Main Results Table 5 Column 7
********************************************************************************

use finaldatasetforregressions.dta, clear
drop if monopoly == 1

xtreg mmc_ek markets_served_origin_TKT markets_served_dest_TKT markets_served_origin_TKTAA-markets_served_dest_TKTYX dummy*, fe vce(robust)	

predict residual_mmc, e

*networks plus competitor's weather plus competitor's regional networks
xtreg csc_weighted_avg markets_served_origin_TKT markets_served_dest_TKT markets_served_origin_TKTAA-markets_served_dest_TKTYX IVm_worstprcp-IVm_worsttmin IVmktktlevl_airportinUS_reg dummy*, fe vce(robust)

predict residual_csc, e

*networks plus own weather
xtreg pct_major_ind markets_served_origin_TKT markets_served_dest_TKT markets_served_origin_TKTAA-markets_served_dest_TKTYX m_worstprcp-m_worsttmin dummy*, fe vce(robust)

predict residual_regpct, e

*IV reg using control function approach
xtreg logprice mmc_ek csc_weighted_avg pct_major_ind residual_mmc residual_csc residual_regpct markets_served_origin_TKT markets_served_dest_TKT dummy*, fe vce(robust)

matrix csc_weight_coef = (_b[mmc_ek], _b[csc_weighted_avg], _b[pct_major_ind], _b[residual_mmc], _b[residual_csc], _b[residual_regpct])

drop residual_mmc
drop residual_csc
drop residual_regpct

capture program drop weight_control
program define weight_control, rclass
	
	preserve
	
	*take bootstrapped sample
	bsample 
	
	*first-stage regression
	xtreg mmc_ek markets_served_origin_TKT markets_served_dest_TKT markets_served_origin_TKTAA-markets_served_dest_TKTYX dummy*, fe vce(robust)
	
	*find mmc residual from first stage
	predict residual_mmc, e

	xtreg csc_weighted_avg markets_served_origin_TKT markets_served_dest_TKT markets_served_origin_TKTAA-markets_served_dest_TKTYX IVm_worstprcp-IVm_worsttmin IVmktktlevl_airportinUS_reg dummy*, fe vce(robust)

predict residual_csc, e
	
	xtreg pct_major_ind markets_served_origin_TKT markets_served_dest_TKT markets_served_origin_TKTAA-markets_served_dest_TKTYX m_worstprcp-m_worsttmin dummy*, fe vce(robust)

	predict residual_regpct, e
	
	*second stage
	xtreg logprice mmc_ek csc_weighted_avg pct_major_ind residual_mmc residual_csc residual_regpct markets_served_origin_TKT markets_served_dest_TKT dummy*, fe vce(robust)
	
	*save coefficient on mmc_ek
	return scalar mmc_ek_coef = _b[mmc_ek]
	return scalar residual_mmc_coef = _b[residual_mmc]
	return scalar cscweight_coef = _b[csc_weighted_avg]
	return scalar residual_csc_coef = _b[residual_csc]
	return scalar regpct_coef = _b[pct_major_ind]
	return scalar residual_regpct_coef = _b[residual_regpct]
	
	restore
	
end

*bootstrap
simulate mmc_ek_coef = _b[mmc_ek] cscweight_coef = _b[csc_weighted_avg] regpct_coef = _b[pct_major_ind] residual_mmc_coef = _b[residual_mmc] residual_csc_coef = _b[residual_csc] residual_regpct_coef = _b[residual_regpct], reps(1000) seed(1234): weight_control 

bstat, stat(csc_weight_coef)

********************************************************************************
*Main Results Table 5 Column 8
********************************************************************************

use finaldatasetforregressions.dta, clear
drop if monopoly == 1

xtreg mmc_ek markets_served_origin_TKT markets_served_dest_TKT markets_served_origin_TKTAA-markets_served_dest_TKTYX dummy*, fe vce(robust)	

predict residual_mmc, e

*networks plus competitor's weather plus competitor's regional networks
xtreg csc_avg markets_served_origin_TKT markets_served_dest_TKT markets_served_origin_TKTAA-markets_served_dest_TKTYX IVm_worstprcp-IVm_worsttmin IVmktktlevl_airportinUS_reg dummy*, fe vce(robust)

predict residual_csc, e

*networks plus own weather
xtreg pct_major_ind markets_served_origin_TKT markets_served_dest_TKT markets_served_origin_TKTAA-markets_served_dest_TKTYX m_worstprcp-m_worsttmin dummy*, fe vce(robust)

predict residual_regpct, e

xtreg regional_mkt_hhi markets_served_origin_TKT markets_served_dest_TKT markets_served_origin_TKTAA-markets_served_dest_TKTYX IVm_worstprcp-IVm_worsttmin IVmktktlevl_airportinUS_reg dummy*, fe vce(robust)

predict residual_hhi, e

*IV reg using control function approach
xtreg logprice mmc_ek csc_avg pct_major_ind regional_mkt_hhi residual_mmc residual_csc residual_regpct residual_hhi markets_served_origin_TKT markets_served_dest_TKT dummy*, fe vce(robust)

matrix hhi_control_coef = (_b[mmc_ek], _b[csc_avg], _b[pct_major_ind], _b[regional_mkt_hhi], _b[residual_mmc], _b[residual_csc], _b[residual_regpct], _b[residual_hhi])

drop residual_mmc
drop residual_csc
drop residual_regpct
drop residual_hhi

capture program drop hhi_control
program define hhi_control, rclass
	
	preserve
	
	*take bootstrapped sample
	bsample 
	
	*first-stage regression
	xtreg mmc_ek markets_served_origin_TKT markets_served_dest_TKT markets_served_origin_TKTAA-markets_served_dest_TKTYX dummy*, fe vce(robust)
	
	*find mmc residual from first stage
	predict residual_mmc, e

	xtreg csc_avg markets_served_origin_TKT markets_served_dest_TKT markets_served_origin_TKTAA-markets_served_dest_TKTYX IVm_worstprcp-IVm_worsttmin IVmktktlevl_airportinUS_reg dummy*, fe vce(robust)

predict residual_csc, e
	
	xtreg pct_major_ind markets_served_origin_TKT markets_served_dest_TKT markets_served_origin_TKTAA-markets_served_dest_TKTYX m_worstprcp-m_worsttmin dummy*, fe vce(robust)

	predict residual_regpct, e

	xtreg regional_mkt_hhi markets_served_origin_TKT markets_served_dest_TKT markets_served_origin_TKTAA-markets_served_dest_TKTYX IVm_worstprcp-IVm_worsttmin IVmktktlevl_airportinUS_reg dummy*, fe vce(robust)

predict residual_hhi, e

	*second stage
	xtreg logprice mmc_ek csc_avg pct_major_ind regional_mkt_hhi residual_mmc residual_csc residual_regpct residual_hhi markets_served_origin_TKT markets_served_dest_TKT dummy*, fe vce(robust)
	
	*save coefficient on mmc_ek
	return scalar mmc_ek_coef = _b[mmc_ek]
	return scalar residual_mmc_coef = _b[residual_mmc]
	return scalar csc_coef = _b[csc_avg]
	return scalar residual_csc_coef = _b[residual_csc]
	return scalar regpct_coef = _b[pct_major_ind]
	return scalar residual_regpct_coef = _b[residual_regpct]
	return scalar hhi_coef = _b[regional_mkt_hhi]
	return scalar residual_hhi_coef = _b[residual_hhi]
		
	restore
	
end

*bootstrap
simulate mmc_ek_coef = _b[mmc_ek] csc_coef = _b[csc_avg] regpct_coef = _b[pct_major_ind] hhi_coef = _b[regional_mkt_hhi] residual_mmc_coef = _b[residual_mmc] residual_csc_coef = _b[residual_csc] residual_regpct_coef = _b[residual_regpct] residual_hhi_coef = _b[residual_hhi], reps(1000) seed(1234): hhi_control 

bstat, stat(hhi_control_coef)
